package client;

import java.util.Collection;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;

import test.TestFacadeRemote;
import ema.tpjee.banking.model.Bank;
import ema.tpjee.banking.model.Customer;


public final class BankingClient {




	public static void main(final String[] args) throws Exception {

		System.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
		System.setProperty(Context.PROVIDER_URL,"localhost:1099");
		System.setProperty(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");



		TestFacadeRemote facadeBean = (TestFacadeRemote)new InitialContext().lookup("BankingSessionFacade/remote");

		// Initialisation de la base
		facadeBean.populate();

	
		List<Bank> banks = facadeBean.getBanks();
		if (banks != null) {
			for (Bank bank : banks) {
				System.out.println("Liste des clients pour la banque "+ bank.getName() + " :");
				Collection<Customer> customers = bank.getCustomers();
				if (customers == null) {
					System.out.println(" Aucun client");
				} else {
					for (Customer customer : customers) 
						System.out.println("    client: "+ customer.getName());
				}
			}
		} else {
			System.out.println("Aucune banque");
		}
		// Recuperation de la liste des Customers
		System.out.println("");
		System.out.println("Liste des clients + banque :");
		List<Customer> customers = facadeBean.getCustomers();
		if (customers != null) {
			for (Customer Customer : customers) {
				System.out.println("client: " + Customer.getName()
						+ " /banque: " + Customer.getBank().getName());
			}
		}
	}
}
